package com.example.myapplication.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.activity.ShopActivity;
import com.example.myapplication.model.GeneralFood;
import com.squareup.picasso.Picasso;

import java.util.List;

import static com.example.myapplication.activity.ShopActivity.cartFoods;

public class FoodAdapter extends RecyclerView.Adapter<FoodAdapter.ViewHolder> {

    private Context context;

    static class  ViewHolder extends  RecyclerView.ViewHolder{
        ImageView foodImage;
        TextView food_Name;
        TextView price;

        public ViewHolder(View view){
            super(view);
            foodImage = view.findViewById(R.id.order_confirm_iv);
            food_Name = view.findViewById(R.id.order_confirm_tv);
            price = view.findViewById(R.id.order_confirm_price);
        }

    }

    public FoodAdapter(List<GeneralFood> cartFoods,int recyclerview_cart, Context context){
        this.context = context;
        ShopActivity.cartFoods = cartFoods;
    }

    @NonNull
    @Override
    public FoodAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_confirm_item,
                parent, false);

        ViewHolder holder= new ViewHolder(view);
        return  holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        GeneralFood generalFood = cartFoods.get(position);
        Picasso.get().load(cartFoods.get(position).getImage()).fit().into(holder.foodImage);
        holder.food_Name.setText(cartFoods.get(position).getTitle());
        holder.price.setText("￥ "+(Double.toString((cartFoods.get(position).getPrice()))));
    }


    @Override
    public int getItemCount() {
        return cartFoods.size();
    }
}
